package com.vertx.user;

import com.vertx.web.verticle.AbstractImplVerticle;
import io.vertx.config.ConfigRetriever;
import io.vertx.config.ConfigRetrieverOptions;
import io.vertx.config.ConfigStoreOptions;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Future;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import io.vertx.servicediscovery.Record;
import io.vertx.servicediscovery.types.HttpEndpoint;
import io.vertx.serviceproxy.ProxyHelper;
import org.apache.log4j.Logger;
import java.io.File;
import java.util.List;

/**
 * 描述: 用户服务
 * 创建人:hzw
 * 创建时间: 2018/4/26 11:07
 **/
public class MainUserVerticle extends AbstractImplVerticle {

    private static final Logger logger = Logger.getLogger(MainUserVerticle.class);

    private static JsonObject jsonObject;


    @Override
    public void start(Future<Void> startFuture) throws Exception {
        super.start(startFuture);
        //发布服务
        publishHttpEndpoint(jsonObject.getString("api-name"),
                jsonObject.getString("api-address"),
                jsonObject.getInteger("http.port"));
    }

    public static void main(String[] args) {
        try {
            Vertx vertx=Vertx.vertx();
            ConfigStoreOptions file=new ConfigStoreOptions()
                    .setType("file").setFormat("json").setConfig(new JsonObject().put("path","conf"+ File.separator+"config.json"));
            ConfigRetrieverOptions configRetrieverOptions=new ConfigRetrieverOptions().addStore(file);
            ConfigRetriever retriever=ConfigRetriever.create(vertx,configRetrieverOptions);
            retriever.getConfig(rs->{
                logger.info(rs.result().toString());
                jsonObject=rs.result();
                vertx.deployVerticle(MainUserVerticle.class.getName(),new DeploymentOptions().setConfig(jsonObject));
            });

        } catch (Exception e) {
            e.printStackTrace();
            logger.error("启动MainUserVerticle失败!");
        }
    }
}
